<template>
	<div class="components-container">
        <div class="header-form">
            <div class="layui-inline">
                <label class="layui-form-label">角色名称</label>
                 <div class="layui-input-inline">
                <el-input v-model="selectData.NameLike" placeholder="请输入角色名称"></el-input>
                 </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">描述</label>
                 <div class="layui-input-inline">
                <el-input v-model="selectData.DescLike" placeholder="请输入描述"></el-input>
                 </div>
            </div>

            <el-button type="primary" @click="btnSearch">搜索</el-button>
            <el-button @click="btnRepeat" >重置</el-button>
        </div>

         <div>
            <ul class="toolList">
                <li v-if="btnShow(item.BTNVALUE)" v-for="(item, index) in $store.state.btnListCommon" @click="operate(item.BTNVALUE)">
                    <el-button type="primary" :value="item.BTNSHOWNAME" v-text="item.BTNSHOWNAME"></el-button>
                </li>
            </ul>
        </div>

         <!--数据列表-->
        <dataTable :headList="headList" :dataList="list" :pageOrder="pageOrder" @pageChange="pageChange" @selectRow="selectRow"></dataTable>

        <!-- 修改 -->
      <role ref="rol" @refreshData="getData"></role>
      <staEndUse ref="useMain" @refreshData="getData"></staEndUse>
	</div>

</template>
<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/common.scss";

</style>
<script>

import apiBase from "@/api/apiBase.js";
import dataTable from "@/components/Table/DataTable";
import { manage } from "@/mixins/managePage.js";
import staEndUse from "../basic/staEndUse";
import { ORDER } from "@/const/orderConst.js";
import role from "./roleMain";
const ADD = "新增";
const MODIFY = "修改";
const DELETE = "删除";
const INFO = "详情";

export default {
  name: "roleManage",
  mixins: [manage],
  data() {
    return {
      checkedList: true,
      loading: false,

      //order:null,
      btn: null,
      roleName: null,
      roleDec: null,
      type: null,
      sort: null,
      totalNum: null,
      addRoleName: null,
      addRoleDesc: null,
      roleId: null,
      listBtn: [],
      optionsData: [],
      defaultProps: {
        children: "children",
        label: "label"
      },
      currentDefaultProps: [],
      currentList: [],
      btnListIfon: [],
      btnListIfonModify: [],
      checkboxItem: null,
      commandItem: null,
      checkboxRow: null,
      currentBtns: [],
      currentListBtn: [],
      addBtn: null,
      expanded: false,

     

      newList: {},
      fups: [],
     
      addBtnItem: null,
      checked: false,

      loading: false,
      order:null,
      list: [],
      selectData: {},
      roleData: {}
    };
  },
  methods: {
    //功能操作
    operate(order) {
      this.order = order;
      switch (this.order) {
        case ADD:
          this.$refs.rol.open(this.order);
          break;
        case MODIFY:
        case DELETE:        
        case INFO:
          this.$refs.rol.open(this.order, this.currentRow.ROLID);
          break;
        case ORDER.START:
        case ORDER.END:
          this.$refs.useMain.open(this.order, this.currentRow.ROLID);
          break;
        default:
      }
    },
    //获取列项
    getColumns() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Column.GetRoleColumns,
        res => {
          this.headList = res.data.content;
        }
      );
    },
    getData() {
      let Data = JSON.parse(JSON.stringify(this.selectData));
      var data = {
        PageIndex: this.pageOrder.currentPage,
        PageSize: this.pageOrder.pageSize,
        OrderBy: this.pageOrder.orderType,
        OrderByType: this.pageOrder.orderSort,
        Data: Data
      };
      apiBase.DoService(data, apiBase.getApiAdress().Role.Query, res => {
        this.list = res.data.content.OutData;
        this.pageOrder.totalNum = res.data.content.RecordCount;
      });
     // this.getRoles();
    },
 //角色权限
    getRoles() {
      var data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Role.QueryFunction,
        res => {
          let resultsData = res.data.content,
            legendsData = resultsData.map((item, i) => ({
              label: item.FGPVALUE,
              value: item.FGPID,
              children: item.Fups.map(item => ({
                id: item.FUPID,
                label: item.FUPVALUE,
                children: item.Funs.map(item => ({
                  id: item.FUNID,
                  label: item.FUNVALUE,
                  children: item.Btns.map(item => ({
                    id: item.BTNID,
                    label: item.BTNVALUE
                  }))
                }))
              }))
            }));
          this.optionsData = legendsData;
          console.log('optionData',this.optionsData)
        }
      );
    },
    btnSearch() {
      this.getData();
    },
    btnShow(btn) {
      let status = '';
      if (this.currentRow) {
        //console.log(this.currentRow);
        status = this.currentRow.ROLSTATUS;
      }
      switch (btn) {
        case ADD:
          return true;
          break;
        case INFO:
        case MODIFY:
        case DELETE:
          return status !== '';
          break;
        case ORDER.END:
          return status === 'A';
          break;
        case ORDER.START:
          return status === 'B';
        default:
      }
    },
    btnRepeat() {
      this.selectData={};
     this.getData();
    },
    cancel() {
      //取消提交打包信息
      this.$refs.dialog.close();
      this.currentListBtn = [];
      this.$store.state.app.currentBtns = [];
      this.getData()
      console.log( this.currentListBtn )
    },

  
  },
  mounted() {
   
  },

  components: {
    role,
    dataTable,
    staEndUse
  },
  created() {
    this.getColumns();
     this.getData();
     this.getRoles();
  }
};
</script>